package uit.ce03.game_ninja.MainGame;

import uit.ce03.game_ninja.NinjaActivity;
import uit.ce03.game_ninja.R;
import uit.ce03.game_ninja.Static.Static_Const;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class GameOver extends Activity {
	Button bt_choilai,bt_mainmenu,bt_exit;
	MediaPlayer mp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.game_over);
		
		 mp = MediaPlayer.create(this, R.raw.nhac_nen_game_1);
	        if(Static_Const.AmThanh)
	        {
	        	mp.start();
	        	mp.setLooping(true);
	        }
		
		bt_choilai = (Button)findViewById(R.id.over_choilai);
		bt_mainmenu = (Button)findViewById(R.id.over_mainmenu);
		bt_exit = (Button)findViewById(R.id.over_exit);
		
		bt_choilai.getBackground().setAlpha(70);
		bt_mainmenu.getBackground().setAlpha(70);
		bt_exit.getBackground().setAlpha(70);
		
		bt_choilai.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new  Intent(GameOver.this,MainGame_BaseGame.class);
				startActivity(i);
				mp.stop();
				finish();
			}
		});
		bt_mainmenu.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new  Intent(GameOver.this,NinjaActivity.class);
				startActivity(i);
				mp.stop();
				finish();
			}
		});
		bt_exit.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder alertDialog = new AlertDialog.Builder(GameOver.this);
				alertDialog.setTitle("Exit");
				alertDialog.setMessage("Bạn Có Muốn Thoát Ra khỏi Game Không ?");
				alertDialog.setIcon(R.drawable.icon_exit);
				alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						mp.stop();
						finish();
					}
				});
				alertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.cancel();
					}
				});
				alertDialog.show();
				
			}
		});
		
		
	}
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			AlertDialog.Builder alertDialog = new AlertDialog.Builder(GameOver.this);
			alertDialog.setTitle("Exit");
			alertDialog.setMessage("Bạn Có Muốn Thoát Ra khỏi Game Không ?");
			alertDialog.setIcon(R.drawable.icon_exit);
			alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					mp.stop();
					finish();
				}
			});
			alertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					dialog.cancel();
				}
			});
			alertDialog.show();
		}
		return super.onKeyDown(keyCode, event);
	}

}
